package work20241217;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author zdl
 * @date 2024/12/17
 */
class Dog{
    private String name;
    private Integer age;

    public Dog() {
    }

    public Dog(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dog dog = (Dog) o;
        return Objects.equals(name, dog.name) && Objects.equals(age, dog.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public Integer getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(Integer age) {
        this.age = age;
    }

    public String toString() {
        return "Dog{name = " + name + ", age = " + age + "}";
    }
}
public class Demo3 {
    public static void main(String[] args) {
        Set<String> set = new HashSet<>();
        set.add("hello");
        set.add("hello");
        set.add("world");
        set.add("kkk");
        System.out.println(set);

        Set<Dog> set1 = new HashSet<>();
        set1.add(new Dog("小黄",1));
        set1.add(new Dog("小黄",1));
        set1.add(new Dog("小黑",1));
        System.out.println(set1);

    }
}
